﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Galaxian
{
    public static class Collision
    {
        public static void FindCollisions(List<GameObject> allObjects)
        {
            for (int i = 0; i < allObjects.Count; i++)
            {
                for (int j = i + 1; j < allObjects.Count; j++)
                {
                    if (allObjects[i].Position.Equals(allObjects[j].Position) 
                        || ((allObjects[i].Shape.ToString() == "Projectile" && allObjects[j].Shape.ToString() == "Projectile")
                        && ((allObjects[i].Position.X == allObjects[j].Position.X - 1 && (allObjects[i].isEnemy != allObjects[j].isEnemy))
                        &&allObjects[i].Position.Y==allObjects[j].Position.Y)))
                    {
                        
                         if (allObjects[i].CanCollideWith(allObjects[j].Shape) && allObjects[j].CanCollideWith(allObjects[i].Shape))
                         {
                             allObjects[i].IsDestroyed = true;
                             allObjects[j].IsDestroyed = true;
                         }
                    }
                }
            }
        }
    }
}
